package comu.hnevc.zh.testdemo;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;

import com.j256.ormlite.stmt.query.In;

import java.util.Timer;
import java.util.TimerTask;

public class SplashActivity extends AppCompatActivity {
     private SharedPreferences sharedPreferences;
    Handler handler=new Handler(){
        @Override
        public void handleMessage(Message msg) {
            Intent intent=new Intent(SplashActivity.this,LoginActivity.class);
            startActivity(intent);
            finish();

        }
    };




    @SuppressLint("WrongConstant")
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash_activity);
        //MODE_APPEND：模式会检查文件是否存在，存在就往文件追加内容，否则就创建新文件。
        sharedPreferences=getSharedPreferences("data",MODE_APPEND);
        if (sharedPreferences.getBoolean("sp",true)){
            SharedPreferences.Editor editor=sharedPreferences.edit();
            editor.putBoolean("sp",false).commit();
            Timer timer=new Timer();
            timer.schedule(new TimerTask() {
                @Override
                public void run() {
                    handler.sendEmptyMessage(101);

                }
            },3000);
        }else {
            Intent intent=new Intent(SplashActivity.this,LoginActivity.class);
            startActivity(intent);
            finish();
        }


    }
}